package cn.edu.ncut.cs.springboot.springbootdatabase.service.impl;

import cn.edu.ncut.cs.springboot.springbootdatabase.dao.PrisonerRepository;
import cn.edu.ncut.cs.springboot.springbootdatabase.entity.Prisoner;
import cn.edu.ncut.cs.springboot.springbootdatabase.service.PrisonerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;


@Service
public class PrisonerServiceImpl implements PrisonerService {
    @Autowired
    private PrisonerRepository prisonerRepository;
    @Override
    public List<Prisoner> findAll() {
        System.out.println(prisonerRepository.findAll());
        return prisonerRepository.findAll();
    }
    @Override
    public Optional<Prisoner> findById(Integer id) {
        return prisonerRepository.findById(Long.valueOf(id));
    }
    @Override
    public Prisoner savePrisoner(Prisoner prisoner) {
        prisonerRepository.save(prisoner);
        return prisoner;
    }

    @Override
    public void deletePrisoner(Integer id) {
        prisonerRepository.deleteById(Long.valueOf(id));
    }
}